package com.hhh.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhh.Mapper.CategoryMapper;
import com.hhh.Mapper.DishMapper;
import com.hhh.Mapper.SetmealMapper;
import com.hhh.Pojo.Category;
import com.hhh.Pojo.Dish;
import com.hhh.Pojo.Setmeal;
import com.hhh.Service.CategoryService;
import com.hhh.Service.DishService;
import com.hhh.Service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategorySerivce implements CategoryService {

    @Autowired
    CategoryMapper categoryMapper;

//    @Autowired
//    DishService dishService;

//    @Autowired
//    SetmealService setmealService;


    //    查看分类
    @Override
    public IPage<Category> SelectALL(long page, long pageSize) {
        IPage<Category> iPage = new Page<>(page, pageSize);
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        return categoryMapper.selectPage(iPage, wrapper);
    }

    //    加入分类
    @Override
    public Integer Insert(Category category) {

        Integer num = categoryMapper.insert(category);
        return num;
    }

    //    修改分类
    @Override
    public Integer Update(Category category) {

        Integer num = categoryMapper.updateById(category);
        return num;
    }

    //    根据类型查找分类
//    默认类型为菜品，1为菜品
    @Override
    public List<Category> SelectType(Category category) {
        List<Category> arr = new ArrayList<>();
        QueryWrapper<Category> wrapper = new QueryWrapper<>();

        if (category.getType() != null) {
            wrapper.eq("type", category.getType());
            arr = categoryMapper.selectList(wrapper);
        } else {
            wrapper.eq("type", 1);
            arr = categoryMapper.selectList(wrapper);
        }
        return arr;
    }

    @Override
    public Category SelectById(long id) {
        return categoryMapper.selectById(id);
    }


}
